package com.ia.aistream.manager.authen.conf;

import com.ia.aistream.manager.framework.redis.RedisKey;
import lombok.Getter;

import java.util.Objects;

/**
 * @author xiaoyu
 */
@Getter
public enum TokenFrom {
    /**
     * Commander管理网页token
     */
    WEB("fromWeb", RedisKey.authen_token_web_string),

    /**
     * Commander供应商管理后台token
     */
    PARTNER("fromWeb", RedisKey.authen_token_web_string),

    /**
     * 开放接口token
     */
    OPEN_API("fromOpenAPI", RedisKey.authen_token_open_string)
    ;

    /* ****URL中使用加kind访问时对应token的类型**** */
    /**
     * Commander管理网页token 对应FROM_WEB
     */
    private static final String AUTO_KIND = "0";

    private final String claimsKind;

    private final RedisKey redisKey;

    TokenFrom(String claimsKind, RedisKey redisKey) {
        this.claimsKind = claimsKind;
        this.redisKey = redisKey;
    }

    public String getRedisKey(Object... keys) {
        if (redisKey == null) {
            return null;
        }
        return redisKey.getKey(keys);
    }

    /**
     * token 中的claimsKind 转泛型
     *
     * @param kind
     * @return
     */
    public static TokenFrom claimsKindOf(String kind) {
        for (TokenFrom from : TokenFrom.values()) {
            if (Objects.equals(from.getClaimsKind(), kind)) {
                return from;
            }
        }
        return TokenFrom.WEB;
    }
}
